﻿using Synthesize.BaseSet.ServiceInterface.Dtos.Authority.Role;
using Synthesize.BaseSet.ServiceInterface.Query.Authority;
using Library.Common.Model;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using Library.Core.Domain.Repository;
using Synthesize.BaseSet.ServiceInterface.UseCase.Authority;
using Synthesize.BaseSet.ServiceInterface.Dtos.Authority.User;
using System.Collections.Generic;

namespace SMS.WebApi.Areas.BaseSet.Controllers
{
    /// <summary>
    /// 角色
    /// </summary>

    public class RoleController : BaseSetBaseController
    {
        private readonly IRoleQueryService _roleQueryService;
        private readonly IRoleService _roleService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="roleQueryService"></param>
        /// <param name="roleService"></param>
        public RoleController(IRoleQueryService roleQueryService
            , IRoleService roleService)
        {
            _roleQueryService = roleQueryService;
            _roleService = roleService;
        }

        /// <summary>
        /// 获取角色列表信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<BaseApiResult<PageData<GetRoleListOutput>>> GetRolePageList([FromQuery]GetRoleListInput input)
        {
            return _roleQueryService.GetRolePageList(input); 
        }

        /// <summary>
        /// 获取所有角色列表信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public Task<BaseApiResult<List<GetRoleListOutput>>> GetAllList()
        {
            return _roleQueryService.GetAllList();
        }
        
        /// <summary>
        /// 创建角色
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<BaseApiResult<bool>> Create(CreateRoleInput input)
        {
            var res = await _roleService.Create(input);
            return res;
        }

        /// <summary>
        /// 启用或禁用角色
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<BaseApiResult<bool>> ForbidOrEnable(ForbidOrEnableInput input)
        {
            return _roleService.ForbidOrEnable(input); 
        }

        /// <summary>
        /// 更新角色
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<BaseApiResult<bool>> Update(UpdateRoleInput input)
        {
            var res = await _roleService.Update(input);
            return res;
        }

        /// <summary>
        /// 修改角色对应的菜单权限信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<BaseApiResult<bool>> UpdateRoleMenu(UpdateRoleMenuInput input)
        {
            var res = await _roleService.UpdateRoleMenu(input);
            return res;
        }


        /// <summary>
        /// 修改角色对应的用户信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<BaseApiResult<bool>> UpdateRoleUser(UpdateRoleUserInput input)
        {
            var res = await _roleService.UpdateRoleUser(input);
            return res;
        }

        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<BaseApiResult<bool>> DeleteById(SingleDeleteInput input)
        {
            var res = await _roleService.DeleteById(input);
            return res;
        }
        

        /// <summary>
        /// 批量删除角色
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<BaseApiResult<bool>> DeleteByIds(BatchDeleteInput input)
        {
            var res = await _roleService.DeleteByIds(input);
            return res;
        }

        /// <summary>
        /// 删除指定的用户-角色关系
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<BaseApiResult<bool>> DeleteUserRole(DeleteUserRoleInput input)
        {
            var res = await _roleService.DeleteUserRole(input);
            return res;
        }
    }
}

